<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<c:set var="itemId" value="${item.ident}" />

<bean:size collection="${item.components}" id="componentsNumber"/>

<c:set var="accessAllowed" value="true" />
<c:if test="${!empty item.rolesWithAncestors}">
    <atleap:isUserInRole roles="${item.rolesWithAncestors}" var="accessAllowed" />
</c:if>
<c:if test="${accessAllowed}">
    <c:set var="align" value="left" />
    <c:if test="${!empty item.align}">
        <c:set var="align" value="${item.align}"/>
    </c:if>
    <c:set var="target" value="_self" />
    <c:if test="${!empty item.target}">
        <c:set var="target" value="${item.target}"/>
    </c:if>
    <c:set var="inRoot" value="${empty item.parent.parent}" />
    <c:choose>
        <c:when test="${inRoot}">
            <div id="${itemId}" style="margin: 0; padding: 0; border: 0;">
        </c:when>
        <c:otherwise>
            <div id="${itemId}" style="display:none; margin: 0; padding: 0; border: 0;">
        </c:otherwise>
    </c:choose>

    <div id="${itemId}__content" style="margin: 0; padding: 0; border: 0;">
        <atleap:message key="${item.title}" var="titleMsg" ignore="true" />
        <c:if test="${empty titleMsg}">
            <c:set var="titleMsg" value="${item.title}" />
        </c:if>
        <atleap:message key="${item.toolTip}" var="toolTipMsg" ignore="true" />
        <c:if test="${empty toolTipMsg}">
            <c:choose>
                <c:when test="${empty item.toolTip}">
                    <c:set var="toolTipMsg" value="${titleMsg}"/>
                </c:when>
                <c:otherwise>
                    <c:set var="toolTipMsg" value="${item.toolTip}"/>
                </c:otherwise>
            </c:choose>
        </c:if>
        <c:set var="titleOut" value="<span" />
        <c:if test="${!empty item.styleClass}">
            <c:set var="titleOut" value="${titleOut} class=\"${item.styleClass}\"" />
        </c:if>
        <c:if test="${!empty item.style}">
            <c:set var="titleOut" value="${titleOut} style=\"${item.style}\"" />
        </c:if>
        <c:set var="escapedTitleMsg"><c:out value="${titleMsg}" escapeXml="true" /></c:set>
        <c:set var="titleOut" value="${titleOut}>${escapedTitleMsg}</span>" />
        <c:set var="imageId" value="item__${loopStatus.count}__image" />
        <c:set var="image" value="" />
        <c:set var="altImage" value="" />
<%--            At this time if image is not specified, alternate image is also not available. Fix if needed --%>
        <c:if test="${!empty item.image}">
            <atleap:rewriteUrl var="image" href="${item.image}" />
            <c:if test="${!empty item.altImage}">
                <atleap:rewriteUrl var="altImage" href="${item.altImage}" />
            </c:if>
        </c:if>
        <c:set var="url" value="${item.url}" />
        <c:set var="urlIsEmpty" value="${empty url}" />
        <c:if test="${urlIsEmpty}">
            <c:set var="url" value="#" />
        </c:if>
        <c:set var="escapedToolTipMsg"><c:out value="${toolTipMsg}" escapeXml="true" /></c:set>
        <table cellpadding="0" cellspasing="0" border="0" style="margin:0; padding:0;" width="100%">
        <tr>
            <td>
            <div align="${align}" class="singleLevelMenuItem"
                <c:if test="${!empty item.styleId}">
                    id="${item.styleId}"
                </c:if>
                onmouseover="activateDropdownMenuItem(this, 'highlightedDropdownMenuItem');"
                onmouseout="deactivateDropdownMenuItem(this, 'dropdownMenuItem');"
            >
                <a target="${target}" href="${url}" title="${escapedToolTipMsg}"
                    <c:if test="${urlIsEmpty}">
                        onclick="dontProcessDocumentClick = true; return false;"
                    </c:if>
                    <c:if test="${!empty altImage}">
                        onmouseover="MM_swapImage(&#039;${imageId}&#039;, '', &#039;${altImage}&#039;);"
                        onmouseout="MM_swapImage(&#039;${imageId}&#039;, '', &#039;${image}&#039;);"
                    </c:if>
                >
                    <c:if test="${!empty image}">
                        <img id="${imageId}" src="${image}" border="0" title="${escapedToolTipMsg}" alt="${escapedToolTipMsg}" style="vertical-align: middle;" />
                    </c:if>
                    ${titleOut}
                </a>
            </div>
            </td>
            <c:if test="${componentsNumber > 0}">
                <td align="right" width="7">
                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['frontendCssTheme']}/arrow_right.png" />" align="middle" border="0" />
                </td>
            </c:if>
            <c:if test="${componentsNumber == 0}">
                <td align="right" width="7">
                    &nbsp;
                </td>
            </c:if>
        </tr>
        </table>
    </div>
    </div>
</c:if>
